package fr.hoteia.appengine.archetype.server.web.servlet.task;

import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * <p>
 * <a href="HotHandlerTaskServlet.java.html"><i>View Source</i></a>
 * </p>
 *
 * @author Denis GOSSET <a href="http://www.hoteia.com"><i>Hoteia.com</i></a>
 * 
 */
public class HotHandlerTaskServlet extends HttpServlet {

	private static final long serialVersionUID = 1L;

	public void init(ServletConfig sc) throws ServletException {
		synchronized (HotHandlerTaskServlet.class) {
			super.init(sc);
		}
	}

	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	}

	public void service(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
		String path = request.getPathInfo();
		
		if (path.startsWith("/start")) {
			callHoteiaWebSite();
		}
	}

	private void callHoteiaWebSite() {
		
		// http://code.google.com/intl/fr-FR/appengine/docs/java/taskqueue/overview.html
		// http://appengine-cookbook.appspot.com/recipe/hot-handler/
		
		URLConnection urlConnection;
		InputStream httpStream;
		try
		{
		  URL hoteiaURL = new URL("http://www.hoteia.com");
		  urlConnection = hoteiaURL.openConnection();
		  httpStream = urlConnection.getInputStream();
		  httpStream.close();
		}
		catch(MalformedURLException e){
			e.printStackTrace();
		}
		catch(IOException e){
			e.printStackTrace();
		}

	}

}
